<HTML>
<HEAD>
<TITLE> Sets </TITLE>
</HEAD>

<BODY style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">

<A NAME="top"></A>

<TABLE STYLE="text-align: left; margin-left: auto; margin-right: auto; width: 800px;" BORDER="0" CELLPADDING="5" CELLSPACING="2">
<TBODY>
<TR>
  <TD STYLE="background-color: rgb(153, 153, 153); vertical-align: middle; text-align: center;">
  <DIV ALIGN="right">
    <SMALL><SMALL><A HREF="index.html">Index Page</A></SMALL></SMALL>
  </DIV>
  <B>Sets</B> </TD>
</TR>
<TR>
  <TD STYLE="vertical-align: top;">

<H2> Table of Contents
</H2>

<PRE>
   <A HREF="#Sets">Sets</A>
      <A HREF="#Abstract">Abstract</A>
         <A HREF="#Revisions">Revisions</A>
      <A HREF="#Introduction">Introduction</A>
      <A HREF="#Naming Conventions">Naming Conventions</A>
      <A HREF="#Initialization">Initialization</A>
      <A HREF="#Cell functions">Cell functions</A>
      <A HREF="#Unary Functions">Unary Functions</A>
      <A HREF="#Binary Functions">Binary Functions</A>
      <A HREF="#Comparison Functions">Comparison Functions</A>
      <A HREF="#Summary">Summary</A>
         <A HREF="#Initialization0">Initialization</A>
         <A HREF="#Utilities">Utilities</A>
         <A HREF="#Unary">Unary</A>
         <A HREF="#Binary">Binary</A>
         <A HREF="#Comparison">Comparison</A>
         <A HREF="#Set Relationships">Set Relationships</A>

</PRE>

<HR SIZE=3 NOSHADE>

<BR><BR>
<A NAME="Sets"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H1> Sets
</H1><HR SIZE=3 NOSHADE><P><BR><BR><BR>
   Last revised on 2010 MAY 18 by B. V. Semenov.
<P>
 
<BR><BR>
<A NAME="Abstract"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Abstract
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   Sets are SPICE data structures that are a special case of SPICE cells --
   vectors of type double precision, integer, or character -- carrying with
   them their own dimension and knowledge of how many components have been
   used.
<P>
 
<BR><BR>
<A NAME="Revisions"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Revisions
</H3><P><BR><BR>
   September 04, 2002
<P>
 
<UL>
<TT>&#32;&#32;</TT> Initial release for CSPICE.
<BR><BR></UL>
<BR><BR>
<A NAME="Introduction"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Introduction
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   The set data type is a subclass of the more basic CSPICE cell data type.
   In order to understand and use sets, you must first understand how to
   use cells.
<P>
 
   A ``set'' is a character, integer, or double precision cell in which the
   following restrictions are observed:
<P>
 
<UL>
<TT>1.</TT> The elements of a set are distinct: sets never contain duplicate elements.
Character sets are case sensitive. For example, a set may contain all of
the following strings:
<BR><BR></UL>
<PRE>
            "AB", "Ab", "aB", "ab".
</PRE>
<UL>
<TT>2.</TT> The elements of a set are always stored contiguously in the set's data
array.
<BR><BR></UL>
<UL>
<TT>&#32;&#32;</TT> A numeric set's data occupy elements
<BR><BR></UL>
<PRE>
            [SPICE_CELL_CRTLSZ + 1] : [SPICE_CELL_CTRLSZ + n]
</PRE>
<UL>
<TT>&#32;&#32;</TT> of the sets's data array, where n is the cardinality of the set. The ith
element is located at index
<BR><BR></UL>
<PRE>
            [SPICE_CELL_CRTLSZ + i]
</PRE>
<UL>
<TT>&#32;&#32;</TT> The parameter
<BR><BR></UL>
<PRE>
            SPICE_CELL_CTRLSZ
</PRE>
<UL>
<TT>&#32;&#32;</TT> is declared in the CSPICE header SpiceCel.h.
<BR><BR></UL>
<UL>
<TT>&#32;&#32;</TT> In character sets, the ith string element starts at index
<BR><BR></UL>
<PRE>
            [SPICE_CELL_CRTLSZ + i]
</PRE>
<UL>
<TT>&#32;&#32;</TT> and the string ranges between the indices
<BR><BR></UL>
<PRE>
            [SPICE_CELL_CRTLSZ+i][0] : [SPICE_CELL_CRTLSZ+i][length-1]
</PRE>
<UL>
<TT>&#32;&#32;</TT> where length is cell member giving the string length associated with the
set.
<BR><BR></UL>
<UL>
<TT>3.</TT> The elements are sorted in increasing order. In character sets, the
ordering of strings is Fortran-style: trailing blanks are not significant.
<BR><BR></UL>
<UL>
<TT>4.</TT> In CSPICE sets, the cell member isSet has the value SPICETRUE.
<BR><BR></UL>
<BR><BR>
<A NAME="Naming Conventions"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Naming Conventions
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   CSPICE contains several functions which allow sets to be manipulated.
   Type-dependent set functions come in groups of three, one for character
   sets, one for double precision sets, and one for integer sets. The name
   of each type-dependent set routine ends in c_c, d_c, or i_c, according
   to the type of set upon which it operates.
<P>
 
   Thus, <a href="../cspice/insrtc_c.html">insrtc_c</a> inserts an element into a character set, <a href="../cspice/insrtd_c.html">insrtd_c</a> inserts
   an element into a double precision set, and <a href="../cspice/insrti_c.html">insrti_c</a> inserts an element
   into an integer set. We will refer to a class of type-dependent set
   routines by taking the name of any routine in the class and substituting
   an x for the last letter. Thus, the function elemx_c may refer to
   <a href="../cspice/elemc_c.html">elemc_c</a>, <a href="../cspice/elemd_c.html">elemd_c</a>, or <a href="../cspice/elemi_c.html">elemi_c</a>. In specific contexts, we will use the
   specific names of routines. A number of the CSPICE set functions are
   truly generic; these functions operate on a CSPICE set of any data type.
   The names of generic set functions have no final character designating
   data type. For example, the generic function <a href="../cspice/union_c.html">union_c</a> computes the union
   of two CSPICE sets of any data type.
<P>
 
<BR><BR>
<A NAME="Initialization"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Initialization
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   As static variables, CSPICE sets (and all CSPICE cells) are
   automatically initialized effectively before program execution. The set
   attributes data type, maximum size, and if applicable, string length are
   provided when the set is declared via a CSPICE cell declaration macro.
   Unlike their SPICELIB counterparts, no run-time initialization calls are
   required to make a CSPICE set ready for use. Normally, an empty set can
   be filled with data via calls the set insertion function of the
   appropriate data type:
<P>
 
<PRE>
   <a href="../cspice/insrtc_c.html">insrtc_c</a>
   <a href="../cspice/insrtd_c.html">insrtd_c</a>
   <a href="../cspice/insrti_c.html">insrti_c</a>
</PRE>
   However, when working with large sets, it may be more efficient to
   construct the set by populating the set's data array and then sorting
   the array and removing duplicate items. After the set's data array has
   been populated, the function <a href="../cspice/valid_c.html">valid_c</a> may be used to sort and prune the
   array:
<P>
 
<PRE>
   <a href="../cspice/valid_c.html">valid_c</a> ( size, n, &amp;set );
</PRE>
   Here size is the maximum allowed size of the set (normally the declared
   size of the data array) and n is the initial number of elements in the
   data array.
<P>
 
   Efficient population of the set's data array may be done using the
   CSPICE cell ``append'' routines, the CSPICE cell element assignment
   macros, or the element reference macros. See the Cells Required Reading,
   <a href="../req/cells.html">cells.req</a>, for further information. An even faster, but lower level,
   approach would be to use memmove, supplying the set's void pointer
   member ``data'' as a target address.
<P>
 
<BR><BR>
<A NAME="Cell functions"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Cell functions
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   A set is by definition a special kind of cell. Thus any of the general
   cell functions may be used with sets. Sets may be copied using <a href="../cspice/copy_c.html">copy_c</a>,
   and the cardinality of a set may be determined by using <a href="../cspice/card_c.html">card_c</a>. The
   appndx_c functions may be used to add elements to a CSPICE set, provided
   the set is validated prior to use.
<P>
 
   The CSPICE cell assignment, fetch, and element reference macros may be
   used to access data members of any CSPICE set. Note however that direct
   assignment of set elements may cause the set to become unordered or to
   contain duplicate items, in which case it cannot be used with the CSPICE
   set functions until it is validated.
<P>
 
   An example of using the CSPICE cardinality function to define a loop
   bound (where we also use the character cell element reference macro to
   point to the cell's data members):
<P>
 
<PRE>
   printf ( "Winners of the Nobel Prize for Physics:\n" );
 
   for ( i = 0;  i &lt; <a href="../cspice/card_c.html">card_c</a>(nobel);  i++ )
   {
      printf ( "%s\n", SPICE_CELL_ELEM_C( nobel, i ) );
   }
</PRE>
   The integer function <a href="../cspice/size_c.html">size_c</a> returns the size (maximum cardinality) of a
   set. This is useful primarily for predicting situations in which
   overflow can occur.
<P>
 
<BR><BR>
<A NAME="Unary Functions"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Unary Functions
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   Unary functions operate on a single set. Two unary operations are
   supported, both of which may alter the contents of the input set.
<P>
 
<UL>
<TT>1.</TT> The insertion of an element into a set.
<BR><BR></UL>
<UL>
<TT>2.</TT> The removal of an element from a set.
<BR><BR></UL>
   In the following example, the element
<P>
 
<PRE>
   "PLUTO"
</PRE>
   is removed from the character set `planets' and inserted into the
   character set `asteroids'.
<P>
 
<PRE>
   <a href="../cspice/removc_c.html">removc_c</a> ( "PLUTO", &amp;planets   );
   <a href="../cspice/insrtc_c.html">insrtc_c</a> ( "PLUTO", &amp;asteroids );
</PRE>
   If
<P>
 
<PRE>
   "PLUTO"
</PRE>
   is not an element of the set `planets', then the contents of `planets'
   are not changed. Similarly, if
<P>
 
<PRE>
   "PLUTO"
</PRE>
   is already an element of `asteroids', the contents of `asteroids' remain
   unchanged.
<P>
 
   If a set is not large enough to accommodate the insertion of an element,
   the CSPICE error handling mechanism reports the excess.
<P>
 
<BR><BR>
<A NAME="Binary Functions"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Binary Functions
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   Binary functions operate on two input sets to produce a third (distinct)
   output set. The four major algebraic binary set operations are
   supported: UNION, INTERSECTION, DIFFERENCE, and SYMMETRIC DIFFERENCE.
<P>
 
   The UNION of two sets contains every element which is in the first set,
   or in the second set, or in both sets.
<P>
 
<PRE>
   {a,b}        U       {c,d}       =    {a,b,c,d}
   {a,b,c}      U       {b,c,d}     =    {a,b,c,d}
   {a,b,c,d}    U       {}          =    {a,b,c,d}
   {}           U       {a,b,c,d}   =    {a,b,c,d}
   {}           U       {}          =    {}
</PRE>
   The INTERSECTION of two sets contains every element which is in both the
   first set AND in the second set.
<P>
 
<PRE>
   {a,b}        *       {c,d}       =    {}
   {a,b,c}      *       {b,c,d}     =    {b,c}
   {a,b,c,d}    *       {}          =    {}
   {}           *       {a,b,c,d}   =    {}
   {}           *       {}          =    {}
</PRE>
   The DIFFERENCE of two sets contains every element which is in the first
   set, but NOT in the second.
<P>
 
<PRE>
   {a,b}        -       {c,d}       =    {a,b}
   {a,b,c}      -       {b,c,d}     =    {a}
   {a,b,c,d}    -       {}          =    {a,b,c,d}
   {}           -       {a,b,c,d}   =    {}
   {}           -       {}          =    {}
</PRE>
   The SYMMETRIC DIFFERENCE of two sets contains every element which is in
   the first set OR in the second set, but NOT in both sets.
<P>
 
<PRE>
   {a,b}        ^       {c,d}       =    {a,b,c,d}
   {a,b,c}      ^       {b,c,d}     =    {a,d}
   {a,b,c,d}    ^       {}          =    {a,b,c,d}
   {}           ^       {a,b,c,d}   =    {a,b,c,d}
   {}           ^       {}          =    {}
</PRE>
   Each of the functions takes two input sets and returns an output set.
<P>
 
   In CSPICE, the functions carrying out these operations are
   type-independent.
<P>
 
   The following calls
<P>
 
<PRE>
   <a href="../cspice/union_c.html">union_c</a> ( &amp;planets, &amp;asteroids, &amp;result );
   <a href="../cspice/inter_c.html">inter_c</a> ( &amp;planets, &amp;asteroids, &amp;result );
   <a href="../cspice/diff_c.html">diff_c</a>  ( &amp;planets, &amp;asteroids, &amp;result );
   <a href="../cspice/sdiff_c.html">sdiff_c</a> ( &amp;planets, &amp;asteroids, &amp;result );
</PRE>
   respectively place the union, intersection, difference, and symmetric
   difference of the character sets `planets' and `asteroids' into the
   character set `result'.
<P>
 
   In each case, if the output set `result' is not large enough to hold the
   result of the operation, as many elements as will fit are inserted into
   the set, and the CSPICE error handling mechanism reports the excess.
<P>
 
   In each of the binary functions, the output set must be distinct from
   both of the input sets. (All four of the binary operations can be
   performed in place, but not efficiently. Consequently, for the sake of
   consistency, none of the functions work in place.) For example, the
   following calls are invalid.
<P>
 
<PRE>
   <a href="../cspice/union_c.html">union_c</a> ( &amp;current,  &amp;new,      &amp;current );
   <a href="../cspice/inter_c.html">inter_c</a> ( &amp;new,      &amp;current,  &amp;current );
</PRE>
   In each of the examples above, the function may or may not return an
   error. However, the results will almost certainly be wrong.
<P>
 
<BR><BR>
<A NAME="Comparison Functions"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Comparison Functions
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   The comparison functions implement the following tests.
<P>
 
<UL>
<TT>1.</TT> Is a given item a member of a set?
<BR><BR></UL>
<UL>
<TT>2.</TT> Does a given relationship exist between two sets?
<BR><BR></UL>
   In the first case, the SpiceBoolean functions_c <a href="../cspice/elemc_c.html">elemc_c</a>, <a href="../cspice/elemd_c.html">elemd_c</a>, and
   <a href="../cspice/elemi_c.html">elemi_c</a> are true whenever the specified item is an element of the
   specified set, and are false otherwise. Let the character sets `planets'
   and `asteroids' contain the following elements.
<P>
 
<PRE>
   PLANETS            ASTEROIDS
   --------           ----------
   "Earth"            "Apollo"
   "Mars"             "Ceres"
   "Pluto"
   "Venus"
</PRE>
   Then all of the following expressions are true.
<P>
 
<PRE>
   <a href="../cspice/elemc_c.html">elemc_c</a> ( "Earth",  &amp;planets   )
   <a href="../cspice/elemc_c.html">elemc_c</a> ( "Pluto",  &amp;planets   )
   <a href="../cspice/elemc_c.html">elemc_c</a> ( "Ceres",  &amp;asteroids )
</PRE>
   And all of the following expressions are false.
<P>
 
<PRE>
   <a href="../cspice/elemc_c.html">elemc_c</a> ( "Saturn", &amp;planets   )
   <a href="../cspice/elemc_c.html">elemc_c</a> ( "Pluto",  &amp;asteroids )
   <a href="../cspice/elemc_c.html">elemc_c</a> ( "CERES",  &amp;asteroids )
</PRE>
   The SpiceBoolean function <a href="../cspice/set_c.html">set_c</a> is true whenever the specified
   relationship between two sets exists, and is false otherwise.
<P>
 
   In the following example, <a href="../cspice/set_c.html">set_c</a> is used to repeat an operation for as
   long as the integer set `finished' remains a proper subset of the
   integer set `planned'.
<P>
 
<PRE>
   while ( <a href="../cspice/set_c.html">set_c</a>( &amp;finished, "&lt;", &amp;planned )  )
   {
     . . .
   }
</PRE>
   The full list of valid operators is given below.
<P>
 
<PRE>
   Operator     is read
   --------     ---------------------------------------------
   "="          "is equal to (contains the same elements as)"
   "&lt;&gt;"         "is not equal to"
   "&lt;="         "is a subset of"
   "&lt;"          "is a proper subset of"
   "&gt;="         "is a superset of"
   "&gt;"          "is a proper superset of"
</PRE>
   Let the integer sets `a', `b', and `c' contain the following elements.
   Let `e' be an empty integer set.
<P>
 
<PRE>
   a        b        c
   ---      ---      ---
   1        1        1
   2        3        3
   3
   4
</PRE>
   Then all of the following expressions are true.
<P>
 
<PRE>
   <a href="../cspice/set_c.html">set_c</a> ( &amp;b, "=",  &amp;c )      "b is equal to c"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;a, "&lt;&gt;", &amp;c )      "a is not equal to c"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;a, "&gt;",  &amp;b )      "a is a proper superset of b"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;b, "&lt;=", &amp;c )      "b is a subset of c"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;c, "&lt;=", &amp;b )      "c is a subset of b"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;a, "&lt;=", &amp;a )      "a is a subset of a"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;e, "&lt;=", &amp;b )      "e is a subset of b"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;e, "&lt;",  &amp;b )      "e is a proper subset of b"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;e, "&lt;=", &amp;e )      "e is a subset of e"
</PRE>
   And all of the following are false.
<P>
 
<PRE>
   <a href="../cspice/set_c.html">set_c</a> ( &amp;b, "&lt;&gt;",  &amp;c )     "b is not equal to c"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;a, "=",   &amp;c )     "a is equal to c"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;a, "&lt;",   &amp;b )     "a is a proper subset of b"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;b, "&lt;",   &amp;c )     "b is a proper subset of c"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;b, "&gt;=",  &amp;a )     "b is a superset of a"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;a, "&gt;",   &amp;a )     "a is a proper superset of a"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;e, "&gt;=",  &amp;a )     "e is a superset of a"
   <a href="../cspice/set_c.html">set_c</a> ( &amp;e, "&lt;",   &amp;e )     "e is a proper subset of e"
</PRE>
<BR><BR>
<A NAME="Summary"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H2> Summary
</H2><HR ALIGN="LEFT" WIDTH=50% ><P><BR><BR>
   The following table summarizes the set routines in the CSPICE library.
<P>
 
<BR><BR>
<A NAME="Initialization0"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Initialization
</H3><P><BR><BR>
<DL><DT>
<B>
 <a href="../cspice/valid_c.html">valid_c</a> ( size, n, set )
</B><BR><BR>
<DD>
 Validate a set from a CSPICE cell of any data type.<BR>
</DL>
<BR><BR>
<A NAME="Utilities"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Utilities
</H3><P><BR><BR>
<DL><DT>
<B>
 <a href="../cspice/size_c.html">size_c</a> ( cell )
</B><BR><BR>
<DD>
 Return the size of a cell of any data type<BR>
</DL>
<DL><DT>
<B>
 <a href="../cspice/card_c.html">card_c</a> ( cell )
</B><BR><BR>
<DD>
 Return the cardinality of a cell of any data type.<BR>
</DL>
<DL><DT>
<B>
 <a href="../cspice/copy_c.html">copy_c</a> ( orig, copy )
</B><BR><BR>
<DD>
 Copy the contents of a cell.<BR>
</DL>
<BR><BR>
<A NAME="Unary"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Unary
</H3><P><BR><BR>
<DL><DT>
<B>
 insrtx_c ( item, set )
</B><BR><BR>
<DD>
 Insert an item into a set.<BR>
</DL>
<DL><DT>
<B>
 removx_c ( item, set )
</B><BR><BR>
<DD>
 Remove an item from a set.<BR>
</DL>
<BR><BR>
<A NAME="Binary"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Binary
</H3><P><BR><BR>
<DL><DT>
<B>
 <a href="../cspice/union_c.html">union_c</a> ( a, b, c )
</B><BR><BR>
<DD>
 Take the union of two sets of any data type.<BR>
</DL>
<DL><DT>
<B>
 <a href="../cspice/inter_c.html">inter_c</a> ( a, b, c )
</B><BR><BR>
<DD>
 Take the intersection of two sets of any data type.<BR>
</DL>
<DL><DT>
<B>
 <a href="../cspice/diff_c.html">diff_c</a> ( a, b, c )
</B><BR><BR>
<DD>
 Take the difference of two sets of any data type.<BR>
</DL>
<DL><DT>
<B>
 <a href="../cspice/sdiff_c.html">sdiff_c</a> ( a, b, c )
</B><BR><BR>
<DD>
 Take the symmetric difference of two sets of any data type.<BR>
</DL>
<BR><BR>
<A NAME="Comparison"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Comparison
</H3><P><BR><BR>
<DL><DT>
<B>
 elemx_c ( item, set )
</B><BR><BR>
<DD>
 Is an item in a set?<BR>
</DL>
<DL><DT>
<B>
 <a href="../cspice/set_c.html">set_c</a> ( a, rel, b )
</B><BR><BR>
<DD>
 What is the relationship between two sets? Set relationships are listed
below.<BR>
</DL>
<BR><BR>
<A NAME="Set Relationships"></A>
<p align="right"><a href="#top"><small>Top</small></a></p>
<H3> Set Relationships
</H3><P><BR><BR>
<PRE>
   =      is equal to (contains the same elements as)
 
   &lt;&gt;     is not equal to
 
   &lt;=     is a subset of
 
   &lt;      is a proper subset of
 
   &gt;=     is a superset of
 
   &gt;      is a proper superset of
</PRE>

</TD>
</TR>
</TBODY>
</TABLE>

</BODY>

</HTML>
